package object.obj3D.enemy;

import object.obj2D.bullet.IBullet;
import system.Device;
import system.Graphics;
import MD2Model.MD2Model;
import MD2Model.Vector3;

import com.game.R;
import com.game.AI.TerminatorAI;

public class Teminator extends Character {

	static MD2Model s_model;
	static boolean s_wasInit = false;
	
	private static int s_maxHP = 500;
	
	public static void Initialize(){
		if (s_wasInit)
			return;
		s_model = new MD2Model(Graphics.GetGraphics(), 
				Device.GetContext(),R.raw.beast_split_anim, R.raw.beast2, false);
		s_wasInit = true;
		
	}
	
	public Teminator(Vector3 position) throws Exception {
		super(s_model, position);
		if (!s_wasInit)
			throw new Exception("Terminator hasn't initialize");

		SetBound(new float[] {
				-86.325f,	-67.346f,	0,
				85.713f,	-67.346f,	0,
				85.713f,	50.816f,	0,
				-86.325f,	50.816f,	0,
				
				-86.325f,	-67.346f,	85.713f,
				85.713f,	-67.346f,	85.713f,
				85.713f,	50.816f,	85.713f,
				-86.325f,	50.816f,	85.713f
		});
		this.SetScale(0.002f, 0.002f, 0.002f);
		
		m_AI = new TerminatorAI(this);
		MoveTo(new Vector3(0,0,0));
//		InModeMove();
		
	}

	@Override
	public void InModeAttack() {
		// TODO Auto-generated method stub
		m_status = ECharStatus.ATTACK;
		if (model.GetNumAnim() > 1 ){
			model.SetAnimation(1);
			AnimIndex = 1;
		}
		
		// generate bullet here
	}

	@Override
	public void InModeDie() {
		// TODO Auto-generated method stub
		m_status = ECharStatus.DIE;
		if (model.GetNumAnim() > 2 ){
			model.SetAnimation(2);
			AnimIndex = 2;
		}
	}

	@Override
	public void InModeInjured() {
		// TODO Auto-generated method stub
		m_status = ECharStatus.INJURE;
		// may be change to red color....
	}

	@Override
	public void InModeMove() {
		m_status = ECharStatus.MOVE;
		// TODO Auto-generated method stub
		if (model.GetAnimation() > 0){
			model.SetAnimation(0);
			AnimIndex = 0;
		}
	}

	@Override
	public void InModeStand() {
		m_status = ECharStatus.STAND;
		// TODO Auto-generated method stub
		if (model.GetAnimation() > 0)
			model.SetAnimation(0);
		//model.SetActive(false);
	}

	@Override
	public void Update() {
		// TODO Auto-generated method stub
		double currentTime = System.currentTimeMillis();
		if (currentTime - m_dLastUpdate >= 100){
			m_AI.Update();
			
			m_position = m_AI.m_vCurrentPosition;
			this.SetTranslateX( m_AI.m_vCurrentPosition.GetX());
			this.SetTranslateY( m_AI.m_vCurrentPosition.GetY());
			this.SetTranslateZ( m_AI.m_vCurrentPosition.GetZ());
			m_dLastUpdate = currentTime;
		}
		
		super.Update();
	}

	@Override
	public IBullet Fire() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void MoveTo(Vector3 destination) {
		// TODO Auto-generated method stub
		InModeMove();
		float angleY = (float)Math.atan((double)(Math.abs(destination.GetX() - GetTranslateX()))/(Math.abs(destination.GetZ() - GetTranslateZ())));
		angleY *= (180/Math.PI);
		SetRotateOY(90f - angleY);
	}

	static public int GetMaxHP() {
		// TODO Auto-generated method stub
		return s_maxHP;
	}

	
}
